Yacon.widget.TMenu = function(element){
	this.element = element;
};

Yacon.widget.TMenu.prototype = {
	
	getHtml : function(){
		
		var html = "";
		
		if(this.element){
			
			if(this.element.type == "top"){
				html += this.getTopHtml();
			}
			
			else if(this.element.type == "right"){
				html += this.getRightHtml();
			}
			
			else if(this.element.type == "bottom"){
				html += this.getBottomHtml();
			}
				
		}
		
		return html;
		
	},
	
	/* 顶部Panel菜单 */
	getTopHtml: function(){
		
		var html = "";
		
		html += "<div class='panel-actions fix'>";
		
		var buttons = this.element.button;
		var size = buttons.length;
		for(var i=0;i<size;i++){
			var activeBtn = new Yacon.widget.TButton(buttons[i]);
			html += activeBtn.getTopHtml();
		}
		
		html += "</div>";
		
		return html;
		
	},
	
	/* 底部Bottom菜单 */
	getBottomHtml: function(){
		
		var html = "";
		
		html += "<div class='pull-right' isWindowControl='true' style='line-height:29px;'>";
		
		var buttons = this.element.button;
		
		for(var i=0;i<buttons.length;i++){
			html += new Yacon.widget.TButton(buttons[i]).getBottomHtml();
			html += "&nbsp;&nbsp;";
		}
		
		html += "</div>";
		
		return html;
		
	},
	
	/* 右键菜单 */
	getRightHtml: function(id){
		
		if(Yacon.isEmpty(id)){
			id = this.parent.element.id +"-menu";
		}
		
		var html = "";
		
		html += "<div id='"+id+"'>";
		
		html += "<ul class='dropdown-menu' role='menu'>";
		
		var buttons = this.element.button;
		var size = buttons.length;
		for(var i=0;i<size;i++){
			var activeBtn = new Yacon.widget.TButton(buttons[i]);
			html += activeBtn.getRightHtml();
		}
		
		html += "</ul>";
		
		html += "</div>";
		
		return html;
		
	},
	
	/* 顶部点击事件 */
	addTopClick: function(child){
		
		var self = this;
		
		var search = this.parent.page.element.search + " div[lily-id='"+this.parent.elementID+"'][lily-type='"+this.parent.elementType+"']";
		
		if(!Yacon.isEmpty(child)){
			search = search+" "+child+" ";
		}
		
		$(search+" a[lily-player='button']").unbind("click");
		$(search+" a[lily-player='button']").click(function(e){	
			
			var button = new Yacon.widget.TButton($(this));
			
			button.dataSet = self.dataSet;
			button.menu = self;
			button.page = self.page;
			button.component = self.parent;
			
			button.addEvent();
			
		});
		
	},
	
	/* 右键点击事件 */
	addRightClick:function(child){
		
		var self = this;
		
		var search = this.parent.page.element.search + " div[lily-id='"+this.parent.elementID+"'][lily-type='"+this.parent.elementType+"']";
		
		if(!Yacon.isEmpty(child)){
			search = search+" "+child+" ";
		}
		
		$(search+" li[lily-player='button']").unbind("click");
		$(search+" li[lily-player='button']").click(function(e){		
		
			var button = new Yacon.widget.TButton($(this));
			
			button.dataSet = self.dataSet;
			button.menu = self;
			button.page = self.page;
			button.component = self.parent;
			
			button.addEvent();		
		});
		
	},
	
	/* 底部点击事件 */
	addBottomClick:function(child){
		
		var self = this;
		
		var search = this.parent.page.element.search + " div[lily-id='"+this.parent.elementID+"'][lily-type='"+this.parent.elementType+"']";
		
		if(!Yacon.isEmpty(child)){
			search = search+" "+child+" ";
		}
		
		$(search+" button[lily-player='button']").unbind("click");
		$(search+" button[lily-player='button']").click(function(e){
			
			var button = new Yacon.widget.TButton($(this));
			
			button.dataSet = self.dataSet;
			button.menu = self;
			button.page = self.page;
			button.component = self.parent;
			
			button.addEvent();		
		});
		
	}
		
};